<template>
  <div class="personal">
    <router-link :to="`/edit_profile/${id}`">
      <div class="profile">
        <img :src="userinfo.head_img" alt />
        <div class="profile-center">
          <div class="name">
            <span
              class="iconfont"
              :class="{
                iconxingbienan: userinfo.gender == 1,
                iconxingbienv: userinfo.gender == 0,
              }"
            ></span
            >{{ userinfo.nickname }}
          </div>
          <div class="time">
            {{ new Date().toLocaleString() }}
          </div>
        </div>
        <span class="iconfont iconjiantou1"></span>
      </div>
    </router-link>
    <mycell
      title="我的关注"
      desc="关注的用户"
      @click.native="$router.push({ name: 'myfollow' })"
    ></mycell>
    <mycell title="我的跟帖" desc="跟帖/回复"></mycell>
    <mycell
      title="我的收藏"
      desc="文章/视频"
      @click.native="$router.push({ name: 'mystar' })"
    ></mycell>
    <mycell title="设置"></mycell>
    <mybutton type="warning" style="margin-top: 20px" @click="logOut"
      >退出</mybutton
    >
  </div>
</template>

<script>
import mycell from "@/components/mycell";
import mybutton from "@/components/mybutton";
import { userDetails } from "@/apis/user.js";
// 图片的地址时绝对地址，需要后期在图片地址前加上服务器地址才能成功显示，所以引入拼接好的服务器地址
import axios from "@/utils/request";
// import { dateFormat } from "../../utils/myfilters.js";
export default {
  data() {
    return {
      userinfo: {},
      axios,
      id: "",
    };
  },
  // filters: {
  //   dateFormat,
  // },
  components: {
    mycell,
    mybutton,
  },
  mounted() {
    // console.log(this.$route.params.id);
    this.id = this.$route.params.id;
    userDetails(this.id)
      .then((res) => {
        console.log(res);
        if (res.data.message == "获取成功") {
          // 渲染数据，在data中定义一个对象用来接收获取到的数据
          this.userinfo = res.data.data;
          // 图片的地址是个绝对地址，需要手动添加服务器地址，在这里设置的原因：重新设置图片地址，渲染的时候就不用重新拼接
          this.userinfo.head_img =
            axios.defaults.baseURL + this.userinfo.head_img;
        }
      })
      .catch((err) => {
        console.log(err);
      });
    // console.log(new Date().toLocaleString());
  },
  methods: {
    logOut() {
      localStorage.removeItem("mytoken");
      this.$router.push({ name: "index" });
    },
  },
};
</script>

<style lang="less" scoped>
.personal {
  width: 100vw;
  height: 100vh;
  background-color: #eee;
}
a {
  color: #666;
}
.profile {
  display: flex;
  padding: 20px 10px;
  justify-content: space-between;
  align-items: center;
  border-bottom: 5px #ddd solid;

  img {
    width: 70 / 360 * 100vw;
    height: 70 / 360 * 100vw;
    border-radius: 50%;
  }

  .profile-center {
    flex: 1;
    padding: 0 10px;
  }

  .name {
    span {
      color: #75b9eb;
    }
  }

  .time {
    color: #666;
    font-size: 14px;
    margin-top: 5px;
  }
}
</style>